home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 4923 < prev    next >
Encoding:
Text File  |  1996-08-06  |  2.0 KB  |  75 lines

  1. Path: scream.ing.com!news
  2. From: "John C. Lund" <jlund@allaire.com>
  3. Newsgroups: alt.comp.lang.borland-delphi,comp.lang.c++
  4. Subject: Calling a C/C++ DLL from Delphi
  5. Date: Thu, 01 Feb 1996 11:00:26 -0600
  6. Organization: Allaire
  7. Message-ID: <3110F1AA.30A2@allaire.com>
  8. NNTP-Posting-Host: 206.144.133.15
  9. Mime-Version: 1.0
  10. Content-Type: text/plain; charset=us-ascii
  11. Content-Transfer-Encoding: 7bit
  12. X-Mailer: Mozilla 2.0b6a (Win95; I)
  13.  
  14. I've written a simple Delphi program that calls a function in a 
  15. C++ DLL I wrote. The DLL uses a "C" interface that I can call 
  16. from other environments (like VB and C++). Although I can call 
  17. the DLL function from my Delphi app, the parameters passed are 
  18. garbage. I tried the same declarations I found in the Delphi 
  19. libraries, but to no avail.
  20.  
  21. For whatever reason it looks like the parameters are pushed and 
  22. popped from the stack differently beween environments.  I've 
  23. tried declaring the function in Delphi with "stdcall", "cdecl", 
  24. and "pascal". 
  25.  
  26. The parameters expected by the DLL are all LPSTR (i.e. char*), so 
  27. I've tried passing PChar and an array of Char. 
  28.  
  29. Any suggestions?
  30.  
  31.  
  32. ***************
  33. Delphi SNIPPETS
  34. ***************
  35.  
  36. {type, private}
  37. function GetFieldsForTable(
  38.    pcharDataSourceName,
  39.    pcharUsername,
  40.    pcharPassword,
  41.    pcharTableName: pChar
  42.    ): integer;
  43.  
  44. {implementation}
  45. function TODBCInformant.GetFieldsForTable;
  46.    external 'patrik.dll' name 'GetFieldsForTable';
  47.  
  48. {I call the function like this:}
  49. nIndex:= GetFieldsForTable(strpcopy(pcharBuiffer,'Test'),
  50.    strpcopy(pcharBuiffer,''),
  51.    strpcopy(pcharBuiffer,''),
  52.    strpcopy(pcharBuiffer,'Employees'));
  53.  
  54.  
  55. ************
  56. C++ SNIPPETS
  57. ************
  58.  
  59. // My C++ header (.H) declares the prototype like this:
  60. extern "C" INT FAR PASCAL EXPORT GetFieldsForTable(
  61.    LPSTR lpszDataSourceName,
  62.    LPSTR lpszUsername,
  63.    LPSTR lpszPassword,
  64.    LPSTR lpszTableName
  65.    );
  66.  
  67. /*
  68. My implementation uses the same format, and the function is named 
  69. in the exports section of the .DEF file.
  70. */
  71.  
  72.  
  73. -- 
  74. // John C. Lund  jlund@allaire.com  http//:www.allaire.com/
  75.